#include "bbs.h"
#include <QtDebug>

BBS::BBS(Profile * newProfile, QString bbsName){
    name = bbsName;
    state = Stop;
    profile = newProfile;
}

BBS::~BBS(){
    //delete all boards
    int i = boardPool.count();
    while ( i -- > 0)
	delete boardPool[i];
    boardPool.clear();
	
}

QString BBS::display(void){
    return name;
}

Board * BBS::boardAt(int i){
    return boardPool.at(i);
}

Board * BBS::favoriteAt(int i){
    return profile->getFavoriteBoard()->at(i);
}

bool BBS::addBoard(Board * board){
    bool ret = true;
    int i = boardPool.count();
    while ( i -- > 0)
	if (board->id == boardPool[i]->id)
	    break;
    if (i == -1){
	boardPool << board;
	if (board->favorite)
	    profile->addFavoriteBoard(board);
    }
    else
	ret =  false;
    return ret;
}
